<?php

class Login extends CI_Controller {

	function index() 
	{

		$data['main_content'] = 'login/admin_login';
		$this->load->view('includes/template', $data);		

	}

	function validate_admin_credentials() 
	{
		$this->load->model('admin_model');
		$query = $this->admin_model->validate();			
					

			if($query)
			{
					$data = array(
						'username' => $this->input->post('username'),
						'is_logged_in' => true
					);

					$this->session->set_userdata($data);
					redirect('product/index');
			}

			else
			{
				$this->index();
			}	

	}

	function create_member()
	{
		$this->load->library('form_validation');
		$this->form_validation->set_rules('customerFirstname', 'Firstname', 'trim|required');	
		$this->form_validation->set_rules('customerLastname', 'Lastname', 'trim|required');	
		$this->form_validation->set_rules('customerAddressOne', 'Address One', 'trim|required');	
		$this->form_validation->set_rules('customerAddressTwo', 'Address Two', 'trim|required');	
		$this->form_validation->set_rules('customerBirthdate', 'Birthdate', 'trim|required');	
		$this->form_validation->set_rules('customerEmail', 'Email', 'trim|required|valid_email');	
		$this->form_validation->set_rules('customerUsername', 'Username', 'trim|required|min_length[4]');	
		$this->form_validation->set_rules('customerPassword', 'Password', 'trim|required|min_length[4]|max_length[32]');	
		$this->form_validation->set_rules('customerPassword2', 'Confirm Password', 'trim|required|matches[customerPassword]');
	
		if($this->form_validation->run() == FALSE )
		{
			$this->signup();
		}
		else
		{
			$this->load->model('membership_model');
			if($query = $this->membership_model->create_member())
			{
				$data['main_content'] = 'signup_successful';
				$this->load->view('includes/template', $data);
			}
			else
			{
				$this->signup();
			}		
		}
	}

	function logout()
	{
		$this->session->sess_destroy();
		$this->index();
	}

}